/**
  ************************************* Copyright ******************************
  * FileName   : my_protocol.h
  * Version    : v1.0
  * Author     : yychao
  * Date       : 2024-02-18
  * Description:
  * Function List:
  	1. ....
  	   <version>:
  <modify staff>:
  		  <data>:
   <description>:
  	2. ...
  ******************************************************************************
 */

#ifndef __MY_PROTOCOL_H_
#define __MY_PROTOCOL_H_
#include "usart.h"


#if 0
#define M2S_HEAD	(0x5a)
#define S2M_HEAD	(0xa5)
#else
typedef enum {
    M2S_HEAD = 0x5a,
    S2M_HEAD = 0xa5,
} PRO_HEAD;
#endif
#if 0
#define REG_COIL	(0x01)
#define REG_DIS		(0x02)
#define REG_HOLD	(0x03)
#define REG_INPUT	(0x04)
#else
typedef enum {
    REG_COIL = 1,
    REG_DIS,
    REG_HOLD,
    REG_INPUT,
} REG_TYPE;
#endif

#if 0
#define OP_READ			(0x01)
#define OP_RES_READ		(0x02)
#define OP_WRITE		(0x03)
#define OP_RES_WRITE	(0x04)
#define OP_REPORT		(0x05)
#define OP_RES_REPORT	(0x06)
#else
typedef enum {
    OP_READ = 1,
    OP_WRITE,
    OP_RES_READ,
    OP_RES_WRITE,

} OP_TYPE;
#endif

#if 0
#else
typedef enum {
    ERR_NONE= 0,
    ERR_HEAD,
    ERR_ALL_LEN,
    ERR_CRC,
    ERR_OPERATE,
    ERR_REG_TYPE,
    ERR_REG_ADDR,
    ERR_REG_VALUE,
} ERR_CHECK;
#endif
struct pro_number {
    uint8_t head;
    uint8_t all_len;
    uint8_t operate;
    uint8_t reg_type;
    uint8_t reg_num;
    uint8_t reg_start;
    uint8_t crc;

    ERR_CHECK status;
};

typedef enum {
	BEEP = 0,
	FAN1,
	FAN2,
	FAN3,
	RED1,
	RED3,
	BLUE1,
	BLUE3,
	YELLOW1,
	YELLOW2,
}COIL;

typedef enum {
	TEMPER = 0,

}INPUT;
struct pro_data {
    uint8_t coil[20];
    uint8_t dis[20];
    uint16_t hold[20];
    uint16_t input[20];
};
extern struct pro_data pro_data_st;
extern struct pro_data pro_data_tem_st;
void cnn_485_deal(usart_cache* recv);
void protocol_adv(uint8_t *data, uint16_t len);
void my_protocol(uint8_t *data, uint16_t cnt);

void op_read(uint8_t *data, uint8_t len);
void op_write(uint8_t *data, uint8_t len);

#endif


